home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HyperLib 1997 Winter - Disc 1
/
HYPERLIB-1997-Winter-CD1.ISO.7z
/
HYPERLIB-1997-Winter-CD1.ISO
/
オンラインウェア
/
BUS
/
TMCM Software and Labs.sit
/
Software for TMCM 7_95
/
Files for Lab 9
/
Other Examples
/
Graph
< prev
next >
Wrap
Text File
|
1994-05-09
|
2KB
|
60 lines
{ This program draws a graph of the function y=sin(x). It would
be easy to modify it to draw the graph of other functions. }
DECLARE xmin, xmax { the range of values of x displayed on the horizontal axis }
DECLARE ymin, ymax { the range of values of y displayed on the vertical axis }
DECLARE x,y { coordinates of a point on the curve }
DECLARE x_scaled, y_scaled { corresponding coordinates on the screen; the actual
x and y-values are scaled so that the ranges from
xmin to xmax and ymin to ymax just fit in the
turtles 20-by-20 rectangle. }
DECLARE PointsToPlot { number of points to be ploted on the graph;
more points give a more accurate graph. }
{ Set up parameters for the graph }
xmin := -300 { math note: measured in degrees in this program }
xmax := 300
ymin := -2
ymax := 2
PointsToPlot := 100
HideTurtle
PenUp { Draw the horizontal axis }
moveTo(-9,0)
PenDown
moveTo(9,0)
PenUp { Draw the vertical axis }
moveTo(0,-9)
PenDown
moveTo(0,9)
x := xmin { x-value of first point on the curve }
y := sin(x) { corresponding y-valuw }
x_scaled := (x-xmin)/(xmax-xmin) * 18 - 9 { some math }
y_scaled := (y-ymin)/(ymax-ymin) * 18 - 9
PenUp { move to first point on graph }
moveTo(x_scaled,y_scaled)
PenDown
LOOP { Draw the rest of the graph }
x := x + (xmax-xmin)/PointsToPlot
EXIT IF x > xmax
y := sin(x)
x_scaled := (x-xmin)/(xmax-xmin) * 18 - 9 { some math }
y_scaled := (y-ymin)/(ymax-ymin) * 18 - 9
moveTo(x_scaled,y_scaled)
END LOOP